package quiz;

import java.util.ArrayList;
import java.util.Collection;

public class Question {

	/* ================ STATIC METHODS AND VARIABLES ================ */

	public static final int FITB = 0;
	public static final int MC = 1;
	public static final int PICTURE = 2;
	public static final int QR = 3;


	/**
	 * Function sets the DataBase object that will be referenced by all questions
	 * MUST BE CALLED BEFORE ANY QUESTIONS ARE CREATED
	 * @param db - the DataBase object referenced by all accounts 
	 */
	public static void setDataBase(DataBase database){
		db = database;
		db.open();
	}
	public static DataBase db;


	/* ================ STATIC METHODS AND VARIABLES ================ */

	/* ================ PRIVATE INSTANCE VARIABLES ================ */


	private int id;
	private Quiz quiz;
	private String content;
	private int type;
	private int time;
	private int priority;
	private int weight;

	/* ================ PRIVATE INSTANCE VARIABLES ================ */


	/**
	 * Constructor for question. These are the types:
	 * 	public static final int FITB = 0;
	 *  public static final int MC = 1;
	 *  public static final int PICTURE = 2;
	 *  public static final int QR = 3;
	 */
	public Question(int quizID, String content, int type, int time, int priority, int weight) {
		this.quiz = db.getQuiz(quizID);
		this.content = content;
		this.type = type;
		this.time = time;
		this.priority = priority;
		this.weight = weight;
	}
	
	public Question(Quiz quiz, String content, int type, int time, int priority, int weight) {
		this.quiz = quiz;
		this.content = content;
		this.type = type;
		this.time = time;
		this.priority = priority;
		this.weight = weight;
	}

	/* ================ GETTERS ================ */


	@Override
	public String toString() {
		return "Question [id=" + id + ", content=" + content + ", type=" + type
				+ ", time=" + time + ", priority=" + priority + ", weight="
				+ weight + "]";
	}

	public int getID() {
		return id;
	}
	
	public Quiz getQuiz() {
		return this.quiz;
	}

	public String getContent() {
		return content;
	}

	public int getType() {
		return type;
	}

	public int getTime() {
		return time;
	}

	public int getPriority() {
		return priority;
	}

	public int getWeight() {
		return weight;
	}

	public ArrayList<Answer> getAnswers() {
		return db.getAnswersForQuestion(this.id);
	}


	/* ================ GETTERS ================ */

	/* ================ SETTERS ================ */




	public void setID(int id) {
		this.id = id;
	}

	public void setQuiz(int id) {
		this.quiz = db.getQuiz(id);
		db.editQuestion(this);
	}
	
	public void setQuiz(Quiz quiz) {
		this.quiz = quiz;
		db.editQuestion(this);
	}
	
	public void setContent(String content) {
		this.content = content;
		db.editQuestion(this);
	}

	public void setType(int type) {
		this.type = type;
		db.editQuestion(this);
	}

	public void setTime(int time) {
		this.time = time;
		db.editQuestion(this);
	}

	public void setPriority(int priority) {
		this.priority = priority;
		db.editQuestion(this);
	}

	public void setWeight(int weight) {
		this.weight = weight;
		db.editQuestion(this);
	}

	/* ================ SETTERS ================ */



	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((content == null) ? 0 : content.hashCode());
		result = prime * result + id;
		result = prime * result + priority;
		result = prime * result + time;
		result = prime * result + type;
		result = prime * result + weight;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Question other = (Question) obj;
		if (content == null) {
			if (other.content != null)
				return false;
		} else if (!content.equals(other.content))
			return false;
		if (id != other.id)
			return false;
		if (priority != other.priority)
			return false;
		if (time != other.time)
			return false;
		if (type != other.type)
			return false;
		if (weight != other.weight)
			return false;
		return true;
	}




}
